<?php
namespace Tbf\Bundle\CronBundle\Tests;

use Symfony\Component\DependencyInjection\Container;
use Tbf\Bundle\CronBundle\Entity\Cron;

class CronTest extends CronBundleTestCase
{
    public function testRun()
    {
        $task = $this->newTaskMock();
        $task->expects($this->once())->method('run');
        $date_list = $this->newDateListMock();
        $date_list->expects($this->never())->method('next');
        $expect_next_time = new \DateTime();
        $date_list->expects($this->exactly(1))->method('current')->will($this->returnValue($expect_next_time));
        $date_list->expects($this->never())->method('valid');

        $cron = new Cron($date_list,$task);
        $cron->run(new Container(),new \DateTime());
    }
    public function testIsValid()
    {
        $task = $this->newTaskMock();
        $date_list = $this->newDateListMock();
        $date_list->expects($this->once())->method('valid')->will($this->returnValue(true));

        $cron = new Cron($date_list,$task);
        $cron->isValid();
    }
    public function testGetNextTime()
    {
        $task = $this->newTaskMock();
        $date_list = $this->newDateListMock();
        $expect_next_time = new \DateTime();
        $date_list->expects($this->once())->method('current')->will($this->returnValue($expect_next_time));

        $cron = new Cron($date_list,$task);
        $this->assertEquals($expect_next_time,$cron->getNextTime());

    }
}
